﻿/**
 * Created by Guochunjiang on 2018/11/25.
 */
(function () {
    cce.SetText = function (i, mCenter, mCount, mRadius, mColorLines, mAngle, mData) {
        cce.DisplayObject.call(this);
        this.i = i;
    };

    cce.SetText.prototype = Object.create(cce.DisplayObject.prototype);
    cce.SetText.prototype.constructor = cce.SetText;

    cce.SetText.prototype.draw = function () {
        var fontSize = 11;
        this.context.font = fontSize + 'px Microsoft Yahei';
        this.context.textBaseline = "middle"; //设置基线参考点
        this.context.textAlign = "center";  // 文本居中
        this.context.fillStyle = '#000';
        var x = mCenter + mRadius * Math.cos(mAngle * this.i);
        var y = mCenter + mRadius * Math.sin(mAngle * this.i);
        var s_width = this.context.measureText(mData[this.i].name).width; //获取当前绘画的字体宽度、
        if (parseInt(x) == mCenter) {
            if (y > mCenter) {
                this.context.fillText(mData[this.i].name, x, y + fontSize);
            } else {
                this.context.fillText(mData[this.i].name, x, y - fontSize);
            }
        } else if (x > mCenter) {
            this.context.fillText(mData[this.i].name, x + 50, y);
        } else {
            this.context.fillText(mData[this.i].name, x - 50, y);
        }
        this.context.restore();
    };

    cce.SetText.prototype.compareTo = function (target) {
        if (target.minX == null) {
            return null;
        }
        if (this.minX < target.minX) {
            return -1;
        }
        if (this.minX == target.minX) {
            return 0;
        }
        if (this.minX > target.minX) {
            return 1;
        }
        return null;
    };

    cce.SetText.prototype.comparePointX = function (point) {
        debugger;
        if (point.x == null) {
            return null;
        }
        if (this.minX < point.x) {
            return -1;
        }
        if (this.minX == point.x) {
            return 0;
        }
        if (this.minX > point.x) {
            return 1;
        }
        return null;
    };

    cce.SetText.prototype.hasPoint = function (point) {
        debugger
        if (point.x == null || point.y == null) {
            return false;
        }

        var distance = Math.pow(point.x - this.x, 2) + Math.pow(point.y - this.y, 2) - Math.pow(this.radius, 2);

        if (distance < 0) {
            return true;
        } else {
            return false;
        }
    };


}());